// pages/myRecords/myRecords.js
Page({
    data: {
      myPosts: [
        {
          id: 1,
          title: "联想笔记本电脑",
          description: "蓝色外壳，在图书馆三楼靠窗位置遗失，电脑包上有个小熊挂件，内有重要学习资料",
          imageUrl: "/images/laptop.png",
          location: "图书馆三楼",
          publishTime: 1695789000000,
          category: "电子设备",
          type: "lost"
        },
        {
          id: 2,
          title: "校园卡",
          description: "姓名：王小明，学号：2022010101，捡到于一食堂一楼",
          imageUrl: "/images/card.png",
          location: "第一食堂",
          publishTime: 1695825000000,
          category: "校园卡",
          type: "found"
        },
        {
          id: 3,
          title: "《算法导论》教材",
          description: "图书馆借阅的教材，书内有笔记，在2号教学楼302教室遗失",
          imageUrl: "/images/book.png",
          location: "2号教学楼",
          publishTime: 1695699000000,
          category: "书籍资料",
          type: "lost"
        }
      ]
    },
  
    // 返回上一页
    goBack() {
      wx.navigateBack();
    },
  
    // 查看帖子详情
    viewPostDetail(e) {
      const postId = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: `/pages/postDetail/postDetail?id=${postId}`
      });
    },
  
    // 跳转到发布页面
    goToPublish() {
      wx.navigateTo({
        url: '/pages/publish/publish'
      });
    },
  
    // 格式化时间
    formatTime(timestamp) {
      const now = Date.now();
      const diff = now - timestamp;
      const minute = 60 * 1000;
      const hour = 60 * minute;
      const day = 24 * hour;
      const week = 7 * day;
  
      if (diff < minute) {
        return '刚刚';
      } else if (diff < hour) {
        return Math.floor(diff / minute) + '分钟前';
      } else if (diff < day) {
        return Math.floor(diff / hour) + '小时前';
      } else if (diff < week) {
        return Math.floor(diff / day) + '天前';
      } else {
        const date = new Date(timestamp);
        return date.getMonth() + 1 + '月' + date.getDate() + '日';
      }
    },
  
    onLoad(options) {
      // 实际项目中，这里可以从服务器获取当前账号发布的帖子数据
      // 示例中直接使用模拟数据
    }
  });